﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Odyssey.Linq;
using Odyssey.Web.Models;
using SunTzu.Web;
using Rea.Web.Models;

namespace Odyssey.Web.Controllers
{
    public class BussinessController : FrontBaseController
    {
        [Login]
        public ActionResult Apply()
        {
            ViewData.Model = db.form_bussinesses.FirstOrDefault(c => c.AccountId == LoginHelper.CurrentUserId)
                ?? new form_bussiness();
            return View();
        }

        [Login]
        [HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreateBussiness(int? id)
        {
            form_bussiness bussiness = db.form_bussinesses.FirstOrDefault(c => c.AccountId == LoginHelper.CurrentUserId)
                ?? new form_bussiness();
            HTMLHelper.BindModel(bussiness);
            bussiness.AccountId = LoginHelper.CurrentUserId;
            if (bussiness.SaveOrUpdate())
            {
                SetMessage("保存成功！");
            }

            return RedirectToAction("Apply");
        }
    }
}
